#!/usr/bin/env node
import { spawn } from 'child_process';
import { Env } from '../core/env.js';
import { Command } from './utils/cli-handler.js';
import { packageJson, IS_WINDOWS } from './utils/utils.js';
import { logger } from '../core/logger.js';
import { color } from '../core/color.js';

const command = new Command("robox");
var robox_default = command;
command.description("Execute an authenticated Robo command.").version(packageJson.version).positionalArgs(true).handler(handler).parse();
async function handler() {
  const splitAt = process.argv.indexOf("--");
  const verbose = process.argv.includes("--verbose") || process.argv.includes("-v");
  const logger$1 = logger({ level: verbose ? "debug" : "info" }).fork("robox");
  logger$1.debug("Loading environment variables...");
  await Env.load();
  const args = [];
  if (splitAt === -1) {
    args.push("robo", ...process.argv.slice(2));
  } else {
    args.push(...process.argv.slice(splitAt + 1));
  }
  logger$1.debug(color.bold("> " + args.join(" ")));
  const child = spawn(args[0], args.slice(1), {
    stdio: "inherit",
    shell: IS_WINDOWS
  });
  process.on("SIGINT", () => child.kill("SIGINT"));
  process.on("SIGTERM", () => child.kill("SIGTERM"));
  process.on("exit", () => child.kill());
}

export { robox_default as default };
